<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var find = function (p) {
      if (p.length == 0) return 0;
      let dp = Array(26).fill(0);
      console.log(dp)
      let preCode = -1, len = 0;
      for (let i = 0; i < p.length; ++i) {
        let curCode = p.charCodeAt(i) - 97;
        if (i == 0 || (curCode - preCode + 26) % 26 != 1) {
          len = 0;
        }
        dp[curCode] = Math.max(dp[curCode], ++len);
        preCode = curCode;
      }
      return dp.reduce((a, b) => a + b);
    };
    console.log(find("cac"))
  </script>
</body>

</html>